package OS

import (
	"errors"
	"gitee.com/fierce_wolf/go-fox-edge-common/commUtil/String"
	"os/exec"
)

type linuxShell struct {
}

func (e *linuxShell) ExecShell(cmd *exec.Cmd) (string, error) {
	if !Type.IsLinux() {
		return "", errors.New("不是linux环境")
	}

	out, err := execCmd(cmd)
	if err != nil {
		return "", err
	}

	return out.String(), nil
}

func (e *linuxShell) Exec(cmd *exec.Cmd) ([]string, error) {
	out, err := e.ExecShell(cmd)
	if err != nil {
		return nil, err
	}

	lines := String.SplitLines(out)
	return lines, nil
}
